package cn.bob.order.service.impl;

import cn.bob.basic.config.BussinessException;
import cn.bob.basic.utils.CodeGenerateUtils;
import cn.bob.basic.utils.PageList;
import cn.bob.order.domain.OrderPetAcquisition;
import cn.bob.order.domain.OrderProduct;
import cn.bob.order.dto.OrderDto;
import cn.bob.order.mapper.OrderProductMapper;
import cn.bob.order.query.OrderProductQuery;
import cn.bob.order.service.IOrderProductService;
import cn.bob.basic.service.impl.BaseServiceImpl;
import cn.bob.pet.domain.SearchMasterMsg;
import cn.bob.product.domain.Product;
import cn.bob.product.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bob
 * @since 2022-11-03
 */
@Service
public class OrderProductServiceImpl extends BaseServiceImpl<OrderProduct> implements IOrderProductService {

    @Autowired
    private OrderProductMapper orderProductMapper;

    @Autowired
    private ProductMapper productMapper;
    @Override
    public void confirm(OrderDto orderDto) {
        //参数校验
        if (orderDto.getMoney()==null || orderDto.getPayType()==null){
            throw new BussinessException("参数不能为空！！");
        }
        //修改状态
        //修改实际交易金额
        OrderProduct orderProduct = orderProductMapper.findById(orderDto.getId());
        orderProduct.setPrice(orderDto.getMoney());
        orderProduct.setState(1);
        orderProductMapper.update(orderProduct);
    }

    @Override
    public void cancel(Long id) {
        //参数校验传入的参数不为空
        if (id==null){
            throw new BussinessException("参数不能为空！！");
        }
        //修改取消订单  todo 存订单取消日志
        OrderProduct order = orderProductMapper.findById(id);
        order.setState(-1);
        orderProductMapper.update(order);
    }

}
